#include<bits/stdc++.h>
using namespace std;
const int N=3005;
char s[N][N],a[N][N];
int U[N][N],D[N][N],vis[N],loc[N],cnt[2][N][N],nex[N],pos[N];
int n,m;
long long ans;
int cmp(int i, int j){ return nex[i]<nex[j] || (nex[i]==nex[j] && i<j); }
void solve(int n, int m, int c){
	for (int i=1; i<=m; i++)
		for (int j=1,k=1; j<=n; j=k+1){
			while (k+1<=n && a[k+1][i]==a[j][i]) k++;
			for (int l=j; l<=k; l++) U[l][i]=j,D[l][i]=k;
		}
	for (int i=1; i<=n; i++){
		nex[i]=1; pos[i]=i;
		while (nex[i]<m && a[i][m-nex[i]]==a[i][m]) nex[i]++;
	}
	sort(pos+1,pos+1+n,cmp);
	for (int t=1; t<=n; t++){
		int i=pos[t]; vis[i]=1;
		for (int j=m-nex[i]+1; j<=m; j++) loc[U[i][j]]++,loc[D[i][j]]++;
		for (int j=1,cur=0; j<i; j++){
			cur+=loc[j];
			if (!vis[j]) cnt[c][j][i]+=cur;
		}
		for (int j=n,cur=0; j>i; j--){
			cur+=loc[j];
			if (!vis[j]) cnt[c][i][j]+=cur;
		}
		for (int j=1; j<=n; j++) loc[j]=0;
	}
	for (int i=1; i<=n; i++) vis[i]=0;
}
void solve(int L1, int R1, int L2, int R2){
	if (L1==R1 || L2==R2) return;
	int len1=R1-L1+1,len2=R2-L2+1;
	if (len1>=len2){
		int mid=(L1+R1)/2;
		solve(L1,mid,L2,R2);
		solve(mid+1,R1,L2,R2);
		
		for (int i=L1; i<=R1; i++)
			for (int j=L2; j<=R2; j++) a[j-L2+1][i-L1+1]=s[i][j];
		solve(R2-L2+1,mid-L1+1,0);
		for (int i=1; i<=R2-L2+1; i++)
			for (int l=1,r=R1-L1+1; l<r; l++,r--) swap(a[i][l],a[i][r]);
		solve(R2-L2+1,R1-mid,1);
		
		for (int i=1; i<=len2; i++)
			for (int j=i+1; j<=len2; j++){
				if (a[i][R1-mid]==a[i][R1-mid+1] && a[j][R1-mid]==a[j][R1-mid+1]) ans+=cnt[0][i][j]*cnt[1][i][j];
				cnt[0][i][j]=cnt[1][i][j]=0;
			}
	} else {
		int mid=(L2+R2)/2;
		solve(L1,R1,L2,mid);
		solve(L1,R1,mid+1,R2);
		
		for (int i=L1; i<=R1; i++)
			for (int j=L2; j<=R2; j++) a[i-L1+1][j-L2+1]=s[i][j];
		solve(R1-L1+1,mid-L2+1,0);
		for (int i=1; i<=R1-L1+1; i++)
			for (int l=1,r=R2-L2+1; l<r; l++,r--) swap(a[i][l],a[i][r]);
		solve(R1-L1+1,R2-mid,1);
		
		for (int i=1; i<=len1; i++)
			for (int j=i+1; j<=len1; j++){
				if (a[i][R2-mid]==a[i][R2-mid+1] && a[j][R2-mid]==a[j][R2-mid+1]) ans+=cnt[0][i][j]*cnt[1][i][j];
				cnt[0][i][j]=cnt[1][i][j]=0;
			}
	}
}
int main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++) scanf("%s",s[i]+1);
	solve(1,n,1,m);
	printf("%lld\n",ans);
//	cerr<<ans<<endl;
}
/*
3 4
aaaa
aaba
aaaa

5 6
aaaaaa
abaaca
aaaaaa
aazzaa
aazzaa
*/
